Then check the files directory to make sure the .geosjon files are in the working directory.
17.2.1 Example 1 - Community Gardens
The first step is always to import the dataset. Let’s start with the community gardens layer from the Greenprint dataset. .geojson files are a geospatial data file format. We can use st_read() to import the data.
Reading layer `CommunityGardens' from data source
`C:\Dev\EA078_Fall2023\CommunityGardens.geojson' using driver `GeoJSON'
Simple feature collection with 186 features and 12 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: -119.2673 ymin: 32.78017 xmax: -115.5097 ymax: 34.52903
Geodetic CRS: WGS 84
The gardens dataset is 186 observations of 13 variables and is a Geometry type POINT. Let’s make a leaflet map with mouseover labels. Figure 17.1 shows a map of California using `leaflet’. We will start with simple markers. Figure 17.1 shows the result.
Figure 17.2: Potential future habitats listed by California Coastal Conservancy
17.2.3 In-class exercise 3
Modify the visualization to change the Tile layer to something more appropriate. Use the AddProviderTiles() function.
The data from this layer is described at TheNatureConservancy. What does this data layer show? What might be a good addition to this visualization to highlight this data layer?
Reading layer `Biodiversity' from data source
`C:\Dev\EA078_Fall2023\Biodiversity.geojson' using driver `GeoJSON'
Simple feature collection with 2015 features and 6 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -119.4784 ymin: 32.61859 xmax: -114.1312 ymax: 35.80909
Geodetic CRS: WGS 84
This dataset has 6 fields, 2015 features, and is a MULTIPOLYGON geometry type. One of the fields is described as RANK and has a ranking. Let’s make a leaflet visualization using a Rank color palette.
First, make the color palette. This is a factor, rather than a numeric or quantile, so we use the colorFactor() function. I chose the Spectral palette but you can choose any palette you think will work.
Figure 17.3 shows the areas of high and low biodiversity in SoCal. I incorporated a legend, color palette, and used the Positron Tile layer instead of OSM.
leaflet()|>addProviderTiles(provider =providers$CartoDB.Positron)|>addPolygons(data =biodiversity, color =~palBD(RANK))|>addLegend(data =biodiversity, title ='Biodiversity', values =~RANK, pal =palBD)